//
//  DMMineVC.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/14.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMMineVC.h"
#import "DMMineFirstCell.h"
#import "DMMineSecondCell.h"
#import "DMMineThirdCell.h"
#import "DMShareCodeVC.h"
#import "DMMyOrderVC.h"
#import "DMBalanceDetailVC.h"
#import "DMMyTeamVC.h"
#import "DMPersonIntroVC.h"
#import "DMSettingVC.h"
#import "DMAddressListVC.h"
#import "DMWithdrawDepositVC.h"
#import "DMMyServiceVC.h"
#import "DMMemberVC.h"

@interface DMMineVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation DMMineVC

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    //创建动画
    CATransition *animation = [CATransition animation];
    //设置运动轨迹的速度
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    //设置动画类型
    animation.type = kCATransitionFade;
    //设置动画时长
    animation.duration =0.3f;
    //设置运动的方向
    animation.subtype =kCATransitionFromRight;
    //控制器间跳转动画
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:animation forKey:nil];
    
    [self.tableView reloadData];
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startInit];
}

-(void)startInit {
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        // Fallback on earlier versions
    }
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMineFirstCell" bundle:nil] forCellReuseIdentifier:@"DMMineFirstCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMineSecondCell" bundle:nil] forCellReuseIdentifier:@"DMMineSecondCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMineThirdCell" bundle:nil] forCellReuseIdentifier:@"DMMineThirdCell"];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0.01;
    }
    return 8;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 265;
    }else if (indexPath.section == 1) {
        return 113;
    }
    return 224;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        DMMineFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMineFirstCell" forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DMMineFirstCell" owner:self options:nil].firstObject;
        }
        [cell.headImage sd_setImageWithURL:[NSURL URLWithString:[KuserInfo shareInstance].userModel.profile] placeholderImage:[UIImage imageNamed:@"moren_touxiang"]];
        cell.nameLb.text = [KuserInfo shareInstance].userModel.nickName;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClickButton:^(NSInteger tag) {
            if (tag == 1) {
                //VIP
            }else if (tag == 2) {
                //二维码
                DMShareCodeVC *vc = [DMShareCodeVC new];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (tag < 6) {
                //我的奖金、我的余额、我的提成
                DMBalanceDetailVC *vc = [DMBalanceDetailVC new];
                vc.flag = tag-3;
                [self.navigationController pushViewController:vc animated:YES];
            }else if (tag == 6) {
                //头像
                DMPersonIntroVC *vc = [DMPersonIntroVC new];
                [self.navigationController pushViewController:vc animated:YES];
            }
        }];
        return cell;
    }else if (indexPath.section == 1) {
        DMMineSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMineSecondCell" forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DMMineSecondCell" owner:self options:nil].firstObject;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClickButton:^(NSInteger tag) {
            DMMyOrderVC *vc = [DMMyOrderVC new];
            vc.index = tag-1;
            [self.navigationController pushViewController:vc animated:YES];
        }];
        return cell;
    }
    DMMineThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMineThirdCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"DMMineThirdCell" owner:self options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setClickButton:^(NSInteger tag) {
        if (tag == 1) {
            //提现收入
            DMWithdrawDepositVC *vc = [DMWithdrawDepositVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tag == 2) {
            //我的团队
            DMMyTeamVC *vc = [DMMyTeamVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tag == 3) {
            //收货地址
            DMAddressListVC *vc = [DMAddressListVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tag == 4) {
            //我的客服
            DMMyServiceVC *vc = [DMMyServiceVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tag == 5) {
            //设置
            DMSettingVC *vc = [DMSettingVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }else if (tag == 6) {
            //会员权益
            DMMemberVC *vc = [DMMemberVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }];
    return cell;
}


@end

